﻿using RedisHelper.Proxy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Pool
{
    class Program
    {
        static void Main(string[] args)
        {
            //获取所有缓存
            List<string> keys = RedisManager.GetAllKeys();


            //.Net操作Redis中的事务与锁
            RedisManager.FlushAll();
            using (var redis = RedisManager.GetClient())
            {
                var tran = redis.CreateTransaction();
                try
                {
                    tran.QueueCommand(p=>
                    {
                        //操作redis数据命令
                        redis.Set<int>("name", 30);
                        long i = redis.IncrementValueBy("name", 1);
                    });
                    //提交事务
                    tran.Commit();
                }
                catch (Exception)
                {
                    //回滚事务
                    tran.Rollback();
                }
                ////操作redis数据命令
                //RedisManager.GetClient().Set<int>("zlh", 30);
                ////声明锁，网页程序可获得锁效果
                //using (redis.AcquireLock("zlh"))
                //{
                //    redis.Set<int>("zlh", 31);
                //    Thread.Sleep(10000);
                //}

            }
            Console.ReadKey();
        }
      
    }
}
